From a40fee45a3ec4fe1741f70f0af80039ee64fea05 Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Tue, 14 Apr 2020 15:33:19 -0600 Subject: [PATCH] Fix access to QByteArray/QString outside the valid range. (#537) With Qt 5.15, and likely 5.14, the following warnings were generated during testo: Using QByteRef with an index pointing outside the valid range of a QByteArray. The corresponding behavior is deprecated, and will be changed in a future version of Qt. Using QCharRef with an index pointing outside the valid range of a QString. The corresponding behavior is deprecated, and will be changed in a future version of Qt. Note this requires Qt to be compiled for debug. These warnings can be debugged by running testo with "export QT_FATAL_WARNINGS=1" to generate core dumps. I suspect the appending of null terminators in ggv_bin is unecessary, i.e. I beleive QByteArray::resize() in ggv_bin_read_bytes will take care of this. Never the less I slavishly kept adding them just to make certain. --- ggv_bin.cc | 6 +++--- xcsv.cc | 2 -- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/ggv_bin.cc b/ggv_bin.cc index 550bee5ef..40b0b18c3 100644 --- a/ggv_bin.cc +++ b/ggv_bin.cc @@ -84,7 +84,7 @@ GgvBinFormat::ggv_bin_read_text16(QDataStream& stream, QByteArray& buf, const ch { quint16 len = ggv_bin_read16(stream, descr); ggv_bin_read_bytes(stream, buf, len, descr); - buf[len] = 0; + buf.append('\0'); if (global_opts.debug_level > 1) { qDebug() << "ovl: text =" << QString::fromLatin1(buf.constData()).simplified(); } @@ -102,7 +102,7 @@ GgvBinFormat::ggv_bin_read_text32(QDataStream& stream, QByteArray& buf, const ch fatal(MYNAME ": Read error, max len exceeded (%s)\n", descr ? descr : ""); } ggv_bin_read_bytes(stream, buf, len, descr); - buf[len] = 0; + buf.append('\0'); if (global_opts.debug_level > 1) { qDebug() << "ovl: text =" << QString::fromLatin1(buf.constData()).simplified(); } @@ -490,7 +490,7 @@ GgvBinFormat::read() QByteArray buf; ggv_bin_read_bytes(stream, buf, 0x17, "magic"); - buf[23] = 0; + buf.append('\0'); if (global_opts.debug_level > 1) { qDebug() << "ovl: header =" << buf.constData(); } diff --git a/xcsv.cc b/xcsv.cc index 61ce7bc41..4fffd7b9f 100644 --- a/xcsv.cc +++ b/xcsv.cc @@ -983,8 +983,6 @@ XcsvFormat::xcsv_waypt_pr(const Waypoint* wpt) double utme, utmn; char utmzc; - buff[0] = '\0'; - if (oldlon < 900) { pathdist += radtomiles(gcdist(RAD(oldlat),RAD(oldlon), RAD(wpt->latitude),RAD(wpt->longitude))); -- 2.30.2